package com.yz.lzq.liwushuo.fragment;

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;

import com.facebook.drawee.backends.pipeline.Fresco;
import com.yz.lzq.liwushuo.R;
import com.yz.lzq.liwushuo.adapter.CategoryGongLHeaderAdapter;
import com.yz.lzq.liwushuo.adapter.CategorygongLAdapter;
import com.yz.lzq.liwushuo.decoration.SpacesItemDecoration;
import com.yz.lzq.liwushuo.persenter.CategoryGongLPresenter;
import com.yz.lzq.liwushuo.view.ICategoryGongLView;

import butterknife.Bind;
import butterknife.ButterKnife;


/**
 * Created by AdminJia on 2016/11/28.
 */

public class CategoryGongLFragment extends Fragment implements ICategoryGongLView {


    @Bind(R.id.recyclerView_category_gongL)
    RecyclerView recyclerViewCategoryGongL;

    @Bind(R.id.recyclerViewCategoryGongLHeader)
    RecyclerView recyclerViewCategoryGongLHeader;

    private Context mContext = null;
    private CategoryGongLPresenter presenter;
    private Button button;

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mContext = getContext();
        Fresco.initialize(mContext);
        presenter = new CategoryGongLPresenter(this);

    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable
            Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_category_gongl, container, false);


        ButterKnife.bind(this, view);

        return view;
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        LinearLayoutManager manager = new LinearLayoutManager(mContext);
        recyclerViewCategoryGongL.addItemDecoration(new SpacesItemDecoration(5));

        recyclerViewCategoryGongL.setNestedScrollingEnabled(false);
        recyclerViewCategoryGongL.setLayoutManager(manager);
        presenter.getHeaderData(mContext);
        presenter.getData(mContext);

    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        ButterKnife.unbind(this);
    }

    @Override
    public void setAdapterSuccess(CategorygongLAdapter adapter) {


        recyclerViewCategoryGongL.setAdapter(adapter);


    }

    @Override
    public void setHeaderAdapter(CategoryGongLHeaderAdapter adapter) {
        GridLayoutManager manager = new GridLayoutManager(mContext, 3);
        recyclerViewCategoryGongLHeader.addItemDecoration(new SpacesItemDecoration(5));
        manager.setOrientation(GridLayoutManager.HORIZONTAL);
        recyclerViewCategoryGongLHeader.setLayoutManager(manager);
        recyclerViewCategoryGongLHeader.setNestedScrollingEnabled(false);
        recyclerViewCategoryGongLHeader.setAdapter(adapter);

    }

    @Override
    public void setAdapterFailec(Throwable t) {

    }


}
